﻿
<template>
<div class="card-fill layout-padding">
<el-card shadow="hover" class="layout-padding-auto" >
  <WtmSearcher v-model="searchDataSimpleData" @search="()=>{getTableDataSimpleData();}">
      <el-row>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="SheetId_FormItem" prop="SheetId" :label="$t('message.autotrans._Model_SimpleData_Sheet')">
            <el-select v-model="searchDataSimpleData.SheetId" clearable>
               <el-option v-for="item in stateSimpleData2.AllSheets" :key="item.Value" :value="item.Value" :label="item.Text"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="BatchId_FormItem" prop="BatchId" :label="$t('message.autotrans._Model_SimpleData_BatchId')">
            <el-input v-model="searchDataSimpleData.BatchId" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="ProductId_FormItem" prop="ProductId" :label="$t('message.autotrans._Model_SimpleData_ProductId')">
            <el-input v-model="searchDataSimpleData.ProductId" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="OpId_FormItem" prop="OpId" :label="$t('message.autotrans._Model_SimpleData_OpId')">
            <el-input v-model="searchDataSimpleData.OpId" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="Sn_FormItem" prop="Sn" :label="$t('message.autotrans._Model_SimpleData_Sn')">
            <el-input v-model="searchDataSimpleData.Sn" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="SimpleValue_FormItem" prop="SimpleValue" :label="$t('message.autotrans._Model_SimpleData_SimpleValue')">
            <el-input v-model="searchDataSimpleData.SimpleValue" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="SimpleTime_FormItem" prop="SimpleTime" :label="$t('message.autotrans._Model_SimpleData_SimpleTime')">
            <el-date-picker v-model="searchDataSimpleData.SimpleTime" type='daterange' clearable></el-date-picker>
        </el-form-item>

        </el-col>
      </el-row>

  </WtmSearcher>

  <div style="text-align: right;">
      <WtmButton v-auth="'/api/SpcManagement/SimpleData/Create'" icon='fa fa-plus' type='primary' :button-text="$t('message.autotrans.SysCreate')" @click="OnCreateClick()"/>
    <WtmButton v-auth="'/api/SpcManagement/SimpleData/BatchDelete'"  icon='fa fa-trash' type='danger' :button-text="$t('message.autotrans.SysDelete')" :confirm="$t('message._system.common.vm.deletetip')" @click="onBatchDelete()"/>
    <WtmButton v-auth="'/api/SpcManagement/SimpleData/BatchEdit'" icon='fa fa-pencil-square' type='primary' :button-text="$t('message.autotrans.SysBatchEdit')" @click="OnBatchEditClick()"/>
    <WtmButton v-auth="'/api/SpcManagement/SimpleData/Import'" icon='fa fa-tasks' type='primary' :button-text="$t('message.autotrans.SysImport')" @click="OnImportClick()"/>
    <WtmButton v-auth="'/api/SpcManagement/SimpleData/SimpleDataExportExcel'"  icon='fa fa-arrow-circle-down' type='primary' :button-text="$t('message.autotrans.SysExport')" @click="onExport()"/>

  </div>
  <WtmTable ref="tableRefSimpleData" v-bind="tableDataSimpleData">
    <template #operation>
      <el-table-column :label="$t('message._system.common.vm.operate')" width="180">
        <template v-slot="scope">
            <WtmButton v-auth="'/api/SpcManagement/SimpleData/Edit'" :is-text="true" icon='fa fa-pencil-square' type='warning' :button-text="$t('message.autotrans.SysEdit')" @click="OnEditrowClick(scope.row)"/>
          <WtmButton v-auth="'/api/SpcManagement/SimpleData/{id}'" :is-text="true" icon='fa fa-info-circle' type='info' :button-text="$t('message.autotrans.Page详情')" @click="OnDetailsrowClick(scope.row)"/>
          <WtmButton v-auth="'/api/SpcManagement/SimpleData/BatchDelete'"  icon='fa fa-trash' type='danger' :button-text="$t('message.autotrans.SysDelete')" :confirm="$t('message._system.common.vm.deletetip')" :is-text="true"  @click="onDelete(scope.row)"/>

        </template>
      </el-table-column>
    </template>
  </WtmTable>

</el-card>
</div>
</template>


<script setup lang="ts" name="message.autotrans._PageSpcManagementSimpleDataIndex;true;Digitalmes.SpcManagement.Controllers;SimpleData">
import {  ElMessageBox, ElMessage,ElLoading } from 'element-plus';
import { defineAsyncComponent,reactive, ref, getCurrentInstance, onMounted, nextTick } from 'vue';
import { simpledataApi } from '/@/api/spcmanagement/simpledata';
import other from '/@/utils/other';
import fileApi from '/@/api/file';
import { useRouter } from "vue-router";
const ci = getCurrentInstance() as any;

const CreateDialog = defineAsyncComponent(() => import('./create.vue'));
const EditDialog = defineAsyncComponent(() => import('./edit.vue'));
const DetailsDialog = defineAsyncComponent(() => import('./details.vue'));
const BatchEditDialog = defineAsyncComponent(() => import('./batchedit.vue'));
const ImportDialog = defineAsyncComponent(() => import('./import.vue'));

const stateSimpleData2 = reactive({
    
    AllSheets: [] as any[],
});

const searchDataSimpleData = ref({
        SheetId: null,
        BatchId: '',
        ProductId: null,
        OpId: null,
        Sn: '',
        SimpleValue: null,
        SimpleTime: undefined,
});

// 定义变量内容
const tableRefSimpleData = ref();
const tableDataSimpleData = ref({
    // 列表数据（必传）
    data: [],
	// 表头内容（必传，注意格式）
	header: [
      {title:ci.proxy.$t('message.autotrans.WumaFORM'),key: 'SimpleData_Sheet',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page批次号'),key: 'SimpleData_BatchId',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page产品'),key: 'SimpleData_ProductId',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page工序'),key: 'SimpleData_OpId',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page追溯码'),key: 'SimpleData_Sn',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page测量值'),key: 'SimpleData_SimpleValue',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page采样时间'),key: 'SimpleData_SimpleTime',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans._AdminIsValid'),key: 'SimpleData_IsValid',type: 'switch',isCheck: true},

	],
	// 配置项（必传）
	config: {
        total: 0, // 列表总数
		loading: true, // loading 加载
		isSerialNo: true, // 是否显示表格序号
		isSelection: true, // 是否显示表格多选
		isOperate: true, // 是否显示表格操作栏
	}
});
// 初始化表格数据
const getTableDataSimpleData = () => {
    tableRefSimpleData.value.doSearch(simpledataApi().search, searchDataSimpleData.value)
        .catch((error: any) => {
			other.setFormError(ci, error);
		});
};
const OnCreateClick = () => {
    other.openDialog(ci.proxy.$t('message.autotrans.SysCreate'), CreateDialog, null, getTableDataSimpleData)
};

const OnEditrowClick = (row: any) => {
    other.openDialog(ci.proxy.$t('message.autotrans.SysEdit'), EditDialog, row, getTableDataSimpleData)
};

const OnDetailsrowClick = (row: any) => {
    other.openDialog(ci.proxy.$t('message.autotrans.Page详情'), DetailsDialog, row, getTableDataSimpleData)
};

// 删除
const onDelete = (row: any) => {
    simpledataApi().delete([row.ID]).then(() => { getTableDataSimpleData()})
};

const onBatchDelete = () => {
    const selectedrows = tableRefSimpleData.value.getSelectedRows();
    const selectedids = selectedrows.map((x: any) => x.ID);
    if (selectedids.length > 0)
      simpledataApi().delete(selectedids).then(() => { getTableDataSimpleData()})
    else
      ElMessage.error(ci.proxy.$t('message._system.common.vm.check'));
};

const OnBatchEditClick = () => {
    const selectedrows = tableRefSimpleData.value.getSelectedRows();
    const selectedids = selectedrows.map((x: any) => x.ID);
    if (selectedids.length > 0)
      other.openDialog(ci.proxy.$t('message.autotrans.SysBatchEdit'), BatchEditDialog, selectedids, getTableDataSimpleData)
    else
      ElMessage.error(ci.proxy.$t('message._system.common.vm.check'));
};

const OnImportClick = () => {
    other.openDialog(ci.proxy.$t('message.autotrans.SysImport'), ImportDialog, null, getTableDataSimpleData)
};

const onExport = () => {
	const selected = tableRefSimpleData.value.getSelectedRows();
	if (selected.length > 0) {
		simpledataApi().exportById(selected.map((x: any) => x.ID));
	}
	else {
		simpledataApi().export({});
	}
};

// 页面加载时
onMounted(() => {
    
    other.getSelectList('/api/SpcManagement/SimpleData/GetSpcAnalysiss',[],false).then(x=>{stateSimpleData2.AllSheets = x});
        getTableDataSimpleData();

});

// 暴露变量
defineExpose({

});
</script>

<style scoped lang="scss">

</style>

